<!-- 注册 -->
<template>
	<!--新用户注册 -->
  <view class="page">
  	<view class="logo">
  		<image src="../../static/logo.png" mode=""></image>
  	</view>
	<view class="other-ways">
			<text>注册</text>
		</view>
		<!-- 登录方式 -->
		<view class="login-way">
			<view class="way">
	<button class="wechatlogin" open-type="getPhoneNumber" @getphonenumber="onRegister"  type="primary">立即注册</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		baseUrl
	} from "../../config/baseUrl.js"
export default {
  data() {
    return {
    };
  },
  methods:{
    /**
     * 注册点击
     */
    onRegister(e){
		if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
			//用户拒绝授权  
			uni.showToast({
				title: '授权已取消',
				icon: 'error',
				mask: true,
			});
		} else {
			let that = this;
			//允许授权
			console.log("iv:", e.detail.iv)
			console.log("encryptedData", e.detail.encryptedData)
			console.log("code:", e.detail.code)
			uni.request({
				url:baseUrl+"/user/weChatRegister",
				method: 'POST',
				data: {
					ivParameter:e.detail.iv,
					encryptedData:e.detail.encryptedData,
				},
				header: {
					"Content-Type": "application/x-www-form-urlencoded"
				},
				success:(res)=>{
					console.log("注册信息:",res.data.userInfo)
					console.log("注册用户ID：",res.data.userId)
					uni.setStorageSync("userId",res.data.userId)
					uni.setStorageSync("userInfo",res.data.userInfo)
					uni.showToast({
						title:"注册成功",
						icon:"success",
						mask:true,
					}),
					uni.switchTab({
						url:'/pages/home/home'
					})
					
				}
			})
		}
    }
  },
  watch:{
    form:{
    }
  }
}
</script>

<style scoped lang="scss">
@import 'register.scss';
</style>
